package io.kiki.sba.registry.server.clientInterface.remoting.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.Node.NodeType;
import io.kiki.sba.registry.common.model.metaserver.ProvideDataChangeEvent;
import io.kiki.sba.registry.server.shared.providedata.SystemPropertyProcessorManager;
import io.kiki.sba.registry.server.shared.remoting.AbstractClientHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;


public class NotifyProvideDataChangeHandler extends AbstractClientHandler<ProvideDataChangeEvent> {

    @Autowired
    ThreadPoolExecutor metaNodeExecutor;

    @Autowired
    SystemPropertyProcessorManager systemPropertyProcessorManager;

    @Override
    protected NodeType getConnectNodeType() {
        return NodeType.central_control;
    }

    @Override
    public Object doHandle(Channel channel, ProvideDataChangeEvent provideDataChangeEvent) {
        final String notifyDataInfoId = provideDataChangeEvent.getDataInfoId();

        // system data do fetch
        systemPropertyProcessorManager.doFetch(notifyDataInfoId);
        return null;
    }

    @Override
    public Class interest() {
        return ProvideDataChangeEvent.class;
    }

    @Override
    public Executor getExecutor() {
        return metaNodeExecutor;
    }
}
